from tkinter import *

fields = '姓名', '年龄', '职业'


def fetch(entries):
    for entry in entries:
        print('输入的文本是：', entry.get())


def make_form(root, fields):
    entries = []
    for field in fields:
        row = Frame(root)
        lab = Label(row, width=5, text=field)
        # 输入框
        ent = Entry(row)
        # 一行
        row.pack(side=TOP, fill=X)
        # 标签
        lab.pack(side=LEFT)
        ent.pack(side=RIGHT, expand=YES, fill=X)
        entries.append(ent)
    return entries


def show(entries, popup):
    """获取数据"""
    fetch(entries)
    popup.destroy()


def ask():
    popup = Toplevel()
    ents = make_form(popup, fields)
    Button(popup, text="确认", command=(lambda: show(ents, popup))).pack()
    popup.grab_set()
    popup.focus_set()
    popup.wait_window()


root = Tk()
Button(root, text='对话框', command=ask).pack()
root.mainloop()
